package com.real.operationalcontrols.适配器;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.real.operationalcontrols.R;
import com.real.operationalcontrols.任务.TaskFinshActivity;
import com.real.operationalcontrols.实体类.WaringListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class TaskYesAdapter extends RecyclerView.Adapter<TaskYesAdapter.ViewHolder> {
    Context context;
    List<WaringListBean.TasklistBean> data = new ArrayList<>();

    public TaskYesAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<WaringListBean.TasklistBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_task_yes,
                viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.tvMessageTitle.setText(data.get(position).getAddress());
        holder.tvMessageContext.setText("报警时间：" + data.get(position).getTime());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(context, TaskFinshActivity.class);
                i.putExtra("id", data.get(position).getId());
                context.startActivity(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_arlm)
        ImageView imgArlm;
        @BindView(R.id.tv_message_title)
        TextView tvMessageTitle;
        @BindView(R.id.tv_message_context)
        TextView tvMessageContext;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
